<template>
  <div id="AddLawyer">
    <h3>添加律师</h3>
    <el-form :model="lawyerData" label-width="300px" style="width: 80%" :rules="rules" ref="addForm">
      <el-form-item label="律师姓名" prop="lawyerName" required>
        <el-input v-model="lawyerData.lawyerName"></el-input>
      </el-form-item>
      <el-form-item label="联系电话" required prop="phone">
        <el-input v-model="lawyerData.phone"></el-input>
      </el-form-item>
      <el-form-item label="工作地点" required prop="location">
        <el-input v-model="lawyerData.location"></el-input>
      </el-form-item>
      <el-form-item label="工作年限" required prop="workYear">
        <el-input-number v-model="lawyerData.workYear" :step="1" step-strictly :min="0" :max="60"></el-input-number>
      </el-form-item>
      <el-form-item label="职务" required prop="position">
        <el-input v-model="lawyerData.position"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submit">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {addLawyer} from "@/api/Lawyer";

export default {
  name: "AddLawyer",
  data() {
    return {
      lawyerData: {
        lawyerName: '',
        phone: '',
        workYear: '',
        location: '',
        position: ''
      },
      rules: {
        lawyerName: [{ required: true, message: '请输入律师姓名', trigger: 'blur' }],
        phone: [{ required: true, message: '请输入电话号码', trigger: 'blur' }],
        workYear: [{ required: true, message: '请输入律师工作年限', trigger: 'blur' }],
        location: [{ required: true, message: '请输入工作地址', trigger: 'blur' }],
        position: [{ required: true, message: '请输入律师职务', trigger: 'blur' }]
      }
    }
  },
  mounted() {
  },
  methods: {
    submit() {
      this.$refs.addForm.validate(vali => {
        if (vali) {
          addLawyer(this.lawyerData).then(res => {
            if (res.resultCode === 200) {
              this.$message.success('操作成功')
              this.$router.push('/admin/Lawyer/index')
            }
          })
        } else {
          return false
        }
      })
    }
  }
}
</script>

<style scoped lang="scss">
#AddLawyer {
  margin: 10px;

  h3 {
    text-align: center;
  }
}
</style>
